package com.bw.controller;

import com.bw.domain.ParkRecord;
import com.bw.service.ParkRecordService;
import com.bw.utils.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author bobo棒
 * @date 2025年02月27日 16:31
 */

@Controller
@RequestMapping("record")
public class ParkRecordController {
    @Autowired
    ParkRecordService parkRecordService;

    /**
     * 入场或出场
     * @param parkRecord
     * @return
     */
    @ResponseBody
    @RequestMapping("addOrUpdate")
    public R addOrUpdate(ParkRecord parkRecord) {
        int i = parkRecordService.addOrUpdate(parkRecord);
        return i>0?R.OK():R.ERROR(500,"操作失败");
    }

    /**
     * 跳转到停车记录列表
     *
     * @return
     */
    @RequestMapping("tolist")
    public String tolist() {

        return "record/list";
    }

    /**
     * 查询停车记录
     *
     * @param parkRecord
     * @param page
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping("list")
    public R list(ParkRecord parkRecord, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<ParkRecord> parkRecordList = parkRecordService.list(parkRecord);
        PageInfo<ParkRecord> info = new PageInfo<>(parkRecordList);
        return R.OK(info);

    }
}

